package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Region extends BaseDomain {
    public static final int STATE_NOMAL = 0;//普通状态
    public static final int STATE_HOT = 1;//推荐状态

    private String name;//地区名

    private Region parent;//上级地区

    private int state;//是否为推荐

    public Map toTreeViewMap() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        map.put("lazyLoad", true);//作用是显示+号
        //判断是否是推荐状态
        if (state == STATE_HOT) {
            map.put("tags", new String[]{"推荐"});
        }
        return map;
    }

    //把当前对象信息转发JSON返回,当前对象中多了个属性,名称叫json
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("state", state);
        if (parent != null) {
            map.put("parentId", parent.getId());
            map.put("parentName", parent.getName());
        }
        return JSONUtil.toJSONString(map);
    }
}